package vip.specimen.system.controller.config;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;
import vip.specimen.system.common.annotation.SystemJurisdiction;
import vip.specimen.system.datasource.entity.SystemAliPayEntity;
import vip.specimen.system.datasource.validation.SystemAliPayConfigValidation;
import vip.specimen.system.result.JsonResult;
import vip.specimen.system.service.SystemAliPayConfigService;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * *@Author: 余浪人
 * *@Date：2021/3/25 12:41
 * *@Email:yulangren520@Gmail.com
 * *@QQ:1368419640
 **/
@Api(tags = "配置管理")
@RestController
@RequestMapping(value = "/config/aliPay")
public class AliPayController {
    @Resource
    SystemAliPayConfigService aliPayConfigService;

    @GetMapping
    @RequiresPermissions(value = "config:aliPay:select")
    @ApiOperation(value = "查看支付宝", notes = "获取支付宝的配置信息")
    @SystemJurisdiction(resourceType = "button", permissionName = "查看支付宝配置")
    public JsonResult<SystemAliPayEntity> getConfig() {
        return JsonResult.success(this.aliPayConfigService.getConfig());
    }

    @PostMapping
    @RequiresPermissions(value = "config:aliPay:update")
    @ApiOperation(value = "更新支付宝", notes = "更新支付宝配置信息")
    @SystemJurisdiction(resourceType = "button", permissionName = "更新支付宝配置")
    public JsonResult<SystemAliPayEntity> emailSaveConf(@RequestBody @Valid SystemAliPayConfigValidation emailConfigValidation) {
        return JsonResult.success(this.aliPayConfigService.update(emailConfigValidation));
    }
}
